<?php
namespace Home\Controller;
use Common\Controller\BaseController;
class CommonController extends BaseController {

    /**
     * 架构函数
     * @access public
     */
    public function __construct() {
        //控制器初始化
        parent::__construct();
           $this->getInfo();
        $myinfo = cookie('my_info');
        if($myinfo['aid']){
            $this->assign('my_info',$myinfo);
        }
        $z=M('ziliao');
        $info=$z->where('id=1')->find();
        $this->assign('info1',$info);
        $guanyu=M('pages');
        $guanyu1=$guanyu->select();
          $this->assign('guanyu2',$guanyu1);

                //友情链接
        $you=M('youlian');
        $youlian=$you->where('type=1')->select();
        $this->assign('youlian',$youlian);

        $dibu=$you->where('type=2')->select();
        
        $this->assign('dibu',$dibu);

        $gwcount=count($_SESSION['goods']);
        $this->assign('gwcount',$gwcount);
                 if(isset($_SESSION['userid'])){
          $user=M('user')->where('id='.$_SESSION['userid'])->find();
          $content=$user['content'];
        if(!empty($content)){
          $map['cid']  = array('in',$content);
        }
          else{
           $map['cid']=''; 
          }
          $fenlei=M('category')->where($map)->select();
         foreach ($fenlei as  &$value) {
         $erji=M('category')->where('pid='.$value['cid'])->select();
                   $value['erji']=$erji;
                 
         }}   
               
          $this->assign("fenlei",$fenlei);
              
              if(isset($_SESSION['userid'])){
          $user=M('user')->where('id='.$_SESSION['userid'])->find();
          $linian=$user['linian'];
        if(!empty($linian)){
          $map['id']  = array('in',$linian);
        }else{
           $map['id']=''; 
          }
          $kuanshi=M('kuanshi')->where($map)->select();
     } 


           
  $this->assign("kuanshi",$kuanshi);
    }

    /**
      +----------------------------------------------------------
     * 验证token信息
      +----------------------------------------------------------
     */
    protected function checkToken() {
        if (IS_POST) {
            if (!M("Admin")->autoCheckToken($_POST)) {
                die(json_encode(array('status' => 0, 'info' => '令牌验证失败')));
            }
            unset($_POST[C("TOKEN_NAME")]);
        }
    }


    protected  function  getInfo(){
         $id =$_SESSION['userid'];
         if (isset($id)){
           $info = M('Comments')->where(array('to_uid'=>$id,'status'=>1))->select();
           $num = M('Comments')->where(array('to_uid'=>$id,'status'=>1))->count();  //查询未读的消息
           $this->assign('num',$num);
         }
    }

    

}

?>